package com.cxt.controller;

import com.cxt.dto.OrderDto;
import com.cxt.entity.TripOrder;
import com.cxt.result.Result;
import com.cxt.service.ITripOrderService;
import com.cxt.vo.OrderInfoVo;
import com.cxt.vo.OrderListVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 行程订单表 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2025-02-27
 */
@RestController
@RequestMapping("/tripOrder")
@Slf4j
public class TripOrderController {
    @Autowired
    private ITripOrderService tripOrderService;
    /**
     * 用户查询订单列表
     */
    @GetMapping("/get")
    public Result getTripOrder() {
        log.info("用户查询订单列表");
        OrderListVo orderListVo = tripOrderService.getOrderList();
        return Result.success(orderListVo);
    }
    /**
     * 查询订单详情
     */
    @GetMapping("/getDetail")
    public Result getTripOrderDetail(Long id) {
        log.info("查询订单详情,id:{}", id);
        OrderInfoVo tripOrder = tripOrderService.getOrderVo(id);
        return Result.success(tripOrder);
    }
    /**
     * 模拟支付订单
     */
    @PostMapping("/pay")
    public Result payTripOrder (@RequestBody OrderDto  order){
        log.info("模拟支付订单");
        boolean isPay = tripOrderService.payTripOrder(order);
        if (!isPay) {
            return Result.error("支付失败");
        }else{
            return Result.success("支付成功");
        }
    }
    /**
     * 司机查询订单列表
     */
        @GetMapping("/getDriver")
    public Result getDriverTripOrder() {
        log.info("司机查询订单列表");
        OrderListVo orderListVo = tripOrderService.getOrderListDriver();
        return Result.success(orderListVo);
    }
}
